#include<iostream>
#include<string>
using namespace std;
string s;
int main()
{
	while (cin >> s) {
		int sum = 0;
		for (int i = 0; i < s.size(); i++) {
			sum += s[i] - '0';
		}
		int ans = 0;
		while (sum) {
			ans += sum % 10;
			sum /= 10;
			if (!sum && ans / 10 != 0) {
				sum = ans;
				ans = 0;
			}
		}
		cout << ans << endl;
	}
	return 0;
}